﻿using App.IRepository;
using App.IService;
using App.Model;
using SqlSugar;
using System.Linq.Expressions;

namespace App.Service
{
    public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : class, new()
    {
        //从子类的构造函数中传入
        protected IBaseRepository<TEntity> _iBaseRepository;

        public async Task<bool> CreateAsync(TEntity entity)
        {
            return await _iBaseRepository.CreateAsync(entity);
        }

        public async Task<bool> DeleteAsync(string id)
        {
            return await _iBaseRepository.DeleteAsync(id);
        }
        public async Task<bool> EditAsync(TEntity entity)
        {
            return await _iBaseRepository.EditAsync(entity);
        }

        public async Task<TEntity> FindAsync(string id)
        {
            return await _iBaseRepository.FindAsync(id);
        }

        public async Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> func)
        {
            return await _iBaseRepository.FindAsync(func);
        }

        public async Task<List<TEntity>> QueryAsync()
        {
            return await _iBaseRepository.QueryAsync();
        }

        public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func)
        {
            return await _iBaseRepository.QueryAsync(func);
        }

        public async Task<List<TEntity>> QueryAsync(int pageIndex, int pageSize, RefAsync<int> total)
        {
            return await _iBaseRepository.QueryAsync(pageIndex, pageSize, total);
        }

        public async Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func, int pageIndex, int pageSize, RefAsync<int> total)
        {
            return await _iBaseRepository.QueryAsync(func, pageIndex, pageSize, total);
        }

        public async Task<bool> BatchDeleteAsync(List<string> ids)
        {
            return await _iBaseRepository.BatchDeleteAsync(ids);
        }

        public async Task<bool> BatchPublishAsync(List<string> ids)
        {
            return await _iBaseRepository.BatchPublishAsync(ids);
        }

        public async Task<bool> BatchUnpublishAsync(List<string> ids)
        {
            return await _iBaseRepository.BatchUnpublishAsync(ids);
        }

        public async Task<bool> BatchSoftDeleteAsync(List<string> ids)
        {
            return await _iBaseRepository.BatchSoftDeleteAsync(ids);
        }

        public async Task<bool> BatchRestoreAsync(List<string> ids)
        {
            return await _iBaseRepository.BatchRestoreAsync(ids);
        }

        public async Task<List<Article>> QuerySoftDeletedAsync(Expression<Func<Article, bool>> func)
        {
            return await _iBaseRepository.QuerySoftDeletedAsync(func);
        }

        public async Task<List<Article>> QuerySoftDeletedAsync(int pageIndex, int pageSize, RefAsync<int> total)
        {
            return await _iBaseRepository.QuerySoftDeletedAsync(pageIndex, pageSize, total);
        }
        public async Task<List<Article>> QuerySoftDeletedAsync(Expression<Func<Article, bool>> func, int pageIndex, int pageSize, RefAsync<int> total)
        {
            return await _iBaseRepository.QuerySoftDeletedAsync(func, pageIndex, pageSize, total);
        }
    }
}